package com.yaowk.sfp.system.server.utils;


import com.yaowk.sfp.common.base.model.result.Tree;
import com.yaowk.sfp.system.api.model.Menu;

import java.util.List;

public class MenuUtil {
    /**
     * 格式化树结构返回值
     *
     * @param menus
     * @param tree
     */
    public static void findMenuChildren(List<Menu> menus, Tree<Menu, Long> tree) {
        Long parentId = tree.getValue().getId();
        for (Menu menu : menus) {
            if (parentId.equals(menu.getParentId())) {
                Tree<Menu, Long> n = new Tree<>();
                n.setValue(menu);
                n.setKey(menu.getId());
                n.setLabel(menu.getName());
                boolean result = tree.getChildren().add(n);
                if (result) {
                    findMenuChildren(menus, n);
                }
            }
        }
    }
}
